package com.gxuwz.web.struts2;

import java.util.List;

import javax.annotation.Resource;

import com.gxuwz.annotation.LogMsg;
import com.gxuwz.entity.SysRole;
import com.gxuwz.entity.SysUser;
import com.gxuwz.service.IRoleService;
import com.gxuwz.util.DateUtils;
import com.gxuwz.util.Page;
import com.gxuwz.web.AbstractBaseController;
import com.gxuwz.web.IBaseController;

/**
 * 角色控制器
 * @author 小胡  
 * @date 2017年5月28日
 */
public class RoleController extends AbstractBaseController implements IBaseController{

	private static final long serialVersionUID = -2144190194672222485L;
	
	@Resource
	private IRoleService roleService;
	private SysRole role;
	private List<Integer> ids;	//	获取复选框的值
	
	/**
	 * 角色列表
	 * @return
	 */
	@Override
	public String listPrompt(){		
		Page<SysRole> page = new Page<SysRole>(); //创建分页对象指定泛型		
		page.setOnePageNum(10); //设置单页记录数	
		page.setPageNo(pageNo==null?1:pageNo); //设置当前页数 默认1
		page.setClazz("Role");
		roleService.findForPage(page);		
		request.put("page", page);		
		setPrompt("/WEB-INF/pages/role/role_list.jsp");
		return SUCCESS;
	}
		
	@Override
	@LogMsg(msg = "删除角色")
	public String doBatchDelete(){
		roleService.batchDelete(ids);
		setPrompt("Role_listPrompt.action");
		return "reposition";
	}
	
	@Override
	public String addPrompt(){
		setPrompt("/WEB-INF/pages/role/role_save.jsp");
		return SUCCESS;
	}	
	@Override
	@LogMsg(msg = "新增角色")
	public String doSave(){
		SysUser user = (SysUser) session.get("user");
		role.setCreateUserName(user.getUserName());
		role.setCreateDate(DateUtils.getCurrentDate());
		roleService.save(role);
		setPrompt("Role_listPrompt.action");
		return "reposition";
	}
	
	@Override
	public String updatePrompt(){	
		Integer id = role.getId();
		SysRole role = roleService.load(id);
		session.put("updateRole", role);
		setPrompt("/WEB-INF/pages/role/role_update.jsp");
		return SUCCESS;
	}
	@Override
	@LogMsg(msg = "更新角色")
	public String doUpdate(){
		SysUser user = (SysUser) session.get("user");
		role.setCreateUserName(user.getUserName());
		role.setCreateDate(DateUtils.getCurrentDate());
		roleService.update(role);
		setPrompt("Role_listPrompt.action");
		return "reposition";
	}
	
	

	public SysRole getRole() {
		return role;
	}

	public void setRole(SysRole role) {
		this.role = role;
	}

	public List<Integer> getIds() {
		return ids;
	}

	public void setIds(List<Integer> ids) {
		this.ids = ids;
	}

}
